package com.yuan.blog.controller;

import com.yuan.blog.entity.UserEntity;
import com.yuan.blog.exception.JsonException;
import com.yuan.blog.service.FollowerService;
import com.yuan.blog.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
public class FollowerController {

    @Autowired
    private FollowerService followerService;

    @PostMapping("/followerUser/{userId}")
    public R followerUser(@PathVariable Integer userId, HttpSession session) {
        UserEntity userEntity = (UserEntity) session.getAttribute("loginUser");
        if (userEntity == null) {
            throw new JsonException(301, "请先登录");
        }

        followerService.followerUser(userId,userEntity.getId());

        return R.ok();
    }
}
